package com.cxg.fairy.ec.main.personal.message;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.cxg.fairy.app.AccountManager;
import com.cxg.fairy.delegates.LatteDelegate;
import com.cxg.fairy.net.RestClient;
import com.cxg.fairy.net.callback.ISuccess;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;
import com.cxg.fairy.util.log.LatteLogger;
import com.diabin.latte.ec.R;
import com.diabin.latte.ec.R2;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by CFairy
 */

public class MessageCenterFundsDelegate extends LatteDelegate implements ISuccess{

    private String UUID = AccountManager.getSignUUID();

    @OnClick(R2.id.back_home)
    void onClickBackHome() {
        getSupportDelegate().pop();
    }

    @BindView(R2.id.rv_funds_list)
    RecyclerView mRecyclerView = null;

    @Override
    public Object setLayout() {
        return R.layout.delegate_my_funds;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        RestClient.builder()
                .url("mc/getMcMessageByMcCateId")
                .params("uuid",AccountManager.getSignUUID())
                .params("mcCateId",getArguments().getInt("id"))
                .loader(getContext())
                .success(this)
                .build()
                .post();
    }

    @SuppressWarnings("deprecation")
    @Override
    public void onSuccess(String response) {

        final LinearLayoutManager manager = new LinearLayoutManager(getContext());
        mRecyclerView.setLayoutManager(manager);

        final List<MultipleItemEntity> data = new MessageCenterFundsDataConverter().setJsonData(response).convert();
        final MessageCenterFundsAdapter msgFundsAdapter = new MessageCenterFundsAdapter(data);

        mRecyclerView.setAdapter(msgFundsAdapter);
        mRecyclerView.addOnItemTouchListener(new MessageCenterClickListener(this));
    }
}
